<?php

require("dbconn.php");

//根据需要action值，判断所属操作，执行对应代码

switch ($_GET[action]) {
    case "add"; //添加
//1.获取要添加的信息
        $name = $_POST["name"];
        $tel = $_POST["tel"];
        $email = $_POST["email"];
        $content = $_POST["content"];
        $addtime = time();
//2.信息过滤
//3.拼装添加sql语句，并执行添加操作
        $sql = "insert into liuyan values(null,'{$name}','{$tel}','{$email}','{$addtime}','{$content}')";

        $mysqli->query($sql); //执行操作
//4.判断数据添加是否成功

        //printf("留言成功", $mysqli->insert_id);
        header("location:show.php");//header函数前面不要有输出
        echo "<br/>";
        echo "<br/>";
        echo "<a href='show.php'>浏览新闻</a>";
        break;

    case "del"; //删除
//1获取删除的id
        $id = $_GET['id'];
//2拼装删除sql语句
        $sql = "delete from liuyan where id={$id}";
//3执行语句
        $mysqli->query($sql);
        echo "删除成功" . "<br/><br/><br/>";
        echo "<a href=show.php>返回留言页面</a>";

//4跳转到浏览新闻界面
//header("location:show.php");这部出现错误了 跳转不到指定页面，只能在上面输出 删除成功,做个超链接
        break;

    case "update": //执行修改操作
        //1. 获取要修改的信息
        $name = $_POST["name"];
        $tel = $_POST["tel"];
        $email = $_POST["email"];
        $content = $_POST["content"];
        $id = $_POST['id'];
        $addtime = time();

        //2. 过滤要修改的信息（省略）
        //3. 拼装修改sql语句，并执行修改操作
        $sql = "update liuyan set name='{$name}',tel='{$tel}',email='{$email}',addtime='{$addtime}' where id={$id}";
        //echo $sql;
        $result = $mysqli->query($sql); //执行操作
        if($result){
            echo '操作成功';
        }else{
            echo '操作失败';
        }
        break;
    case "reply"; //添加
//1.获取要添加的信息
        $liu_id =$_POST['liu_id'];
        $name = $_POST["name"];
        $tel = $_POST["tel"];
        $email = $_POST["email"];
        $content = $_POST["content"];
        $addtime = time();
//2.信息过滤
//3.拼装添加sql语句，并执行添加操作
        $sql = "insert into huifu values(null,'{$liu_id}','{$name}','{$tel}','{$email}','{$addtime}','{$content}')";

        $mysqli->query($sql); //执行操作
//4.判断数据添加是否成功

        //printf("回复成功", $mysqli->insert_id);
        header("location:show.php");//header函数前面不要有输出
        echo "<br/>";
        echo "<br/>";
        echo "<a href='show.php'>浏览新闻</a>";
        break;
}






//释放结果集
//关闭数据库连接
$mysqli->close();
?>